package com.ag.oa.core.controller;

import com.ag.oa.core.entity.vo.UserFeedbackVO;
import com.ag.oa.core.service.IUserFeedBackService;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userFeedbackController")
@RequestMapping("/feedback")
public class UserFeedbackController {

    private static final Logger logger = LoggerFactory.getLogger(UserFeedbackController.class);

    @Autowired
    private IUserFeedBackService userFeedBackService;

    @PostMapping("/createFeedback")
    public String createUserFeedback(@RequestBody UserFeedbackVO vo) {
        JSONObject res = new JSONObject();
        int code = 200;
        try {
            userFeedBackService.createUserFeedback(vo);
        } catch (Exception e) {
            code = 500;
            logger.error(e.getMessage(), e);
        }
        res.put("resCode", code);
        return res.toString();
    }

    @GetMapping(value = "/pageList")
    public String getPageList(Integer userId, Integer page) {

        JSONObject res = new JSONObject();
        int code = 200;
        try {
            List<UserFeedbackVO> voList = userFeedBackService.getFeedbackList(userId, page);
            res.put("dataList", voList);
        } catch (Exception e) {
            e.printStackTrace();
            code = 500;
            logger.error(e.getMessage());
        }
        res.put("resCode", code);
        return res.toString();
    }

    @GetMapping(value = "/getFeedbackDetail")
    public String getFeedbackDetail(Integer userId, Integer feedbackId) {

        JSONObject res = new JSONObject();
        int code = 200;
        try {
            UserFeedbackVO feedback = userFeedBackService.getFeedbackDetail(userId, feedbackId);
            res.put("feedback", feedback);
        } catch (Exception e) {
            e.printStackTrace();
            code = 500;
            logger.error(e.getMessage());
        }
        res.put("resCode", code);
        return res.toString();
    }




}
